package com.xbongbong.paas.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.xbongbong.paas.elasticsearch.pojo.dto.SearchBoardConditionDTO;
import com.xbongbong.paas.elasticsearch.pojo.dto.SearchDataInConditionDTO;
import com.xbongbong.paas.elasticsearch.pojo.dto.SearchDataSetInConditionDTO;
import com.xbongbong.paas.field.LinkFormPoJo;
import com.xbongbong.paas.field.RelyPoJo;
import com.xbongbong.paas.pojo.dto.ApprovePrintSubSummaryGetDTO;
import com.xbongbong.paas.pojo.dto.BusinessFormDataDTO;
import com.xbongbong.paas.pojo.dto.ButtonGetDTO;
import com.xbongbong.paas.pojo.dto.CustomerMergeDTO;
import com.xbongbong.paas.pojo.dto.FormCountGetDTO;
import com.xbongbong.paas.pojo.dto.FormDataAddDTO;
import com.xbongbong.paas.pojo.dto.FormDataAddGetDTO;
import com.xbongbong.paas.pojo.dto.FormDataDeleteDTO;
import com.xbongbong.paas.pojo.dto.FormDataFastAddGetDTO;
import com.xbongbong.paas.pojo.dto.FormDataFastUpdateDTO;
import com.xbongbong.paas.pojo.dto.FormDataGetDTO;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.dto.FormDataOwnerDTO;
import com.xbongbong.paas.pojo.dto.FormDataRepeatDTO;
import com.xbongbong.paas.pojo.dto.FormDataSubSummaryGetDTO;
import com.xbongbong.paas.pojo.dto.FormDataSummaryDTO;
import com.xbongbong.paas.pojo.dto.FormDataUpdateDTO;
import com.xbongbong.paas.pojo.dto.FormDataUpdateGetDTO;
import com.xbongbong.paas.pojo.dto.LinkDataListDTO;
import com.xbongbong.paas.pojo.dto.LinkFormDataDTO;
import com.xbongbong.paas.pojo.dto.LinkRelyDataDTO;
import com.xbongbong.paas.pojo.dto.LinkSearchListDTO;
import com.xbongbong.paas.pojo.dto.LinkWorkOrderPhoneDTO;
import com.xbongbong.paas.pojo.dto.SearchInConditionDTO;
import com.xbongbong.paas.pojo.dto.WarehouseCheckDTO;
import com.xbongbong.paas.pojo.vo.ButtonGetVO;
import com.xbongbong.paas.pojo.vo.CheckRepeatVO;
import com.xbongbong.paas.pojo.vo.CustomerMergeVO;
import com.xbongbong.paas.pojo.vo.FormCountGetVO;
import com.xbongbong.paas.pojo.vo.FormDataAddGetVO;
import com.xbongbong.paas.pojo.vo.FormDataAddVO;
import com.xbongbong.paas.pojo.vo.FormDataDeleteVO;
import com.xbongbong.paas.pojo.vo.FormDataFastUpdateVO;
import com.xbongbong.paas.pojo.vo.FormDataGetVO;
import com.xbongbong.paas.pojo.vo.FormDataOwnerVO;
import com.xbongbong.paas.pojo.vo.FormDataSummaryVO;
import com.xbongbong.paas.pojo.vo.FormDataUpdateGetVO;
import com.xbongbong.paas.pojo.vo.FormDataUpdateVO;
import com.xbongbong.paas.pojo.vo.LinkDataListVO;
import com.xbongbong.paas.pojo.vo.LinkFormDataVO;
import com.xbongbong.paas.pojo.vo.LinkRelyDataVO;
import com.xbongbong.paas.pojo.vo.LinkRelyDataWorkOrderPhoneVO;
import com.xbongbong.paas.pojo.vo.LinkSearchListVO;
import com.xbongbong.paas.pojo.vo.PaasFormDataEsListVO;
import com.xbongbong.paas.pojo.vo.SearchDataInConditionVO;
import com.xbongbong.paas.redis.PaasRedisHelper;
import com.xbongbong.paas.service.LinkDataService;
import com.xbongbong.paas.service.PaasFormAttrTrashService;
import com.xbongbong.paas.service.PaasFormDataService;
import com.xbongbong.paas.service.ProFormDataService;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.thread.TransmittableThreadLocalUtil;
import com.xbongbong.paas.toolbox.wrap.BaseVO;
import com.xbongbong.paas.toolbox.wrap.XbbResponse;
import com.xbongbong.parent.interfaces.BusinessDetailBaseInfoService;
import com.xbongbong.pro.businessdata.pojo.dto.ProductListDataDTO;
import com.xbongbong.pro.businessdata.pojo.dto.SpecificationHistoryDTO;
import com.xbongbong.pro.businessdata.pojo.vo.SpecificationHistoryVO;
import com.xbongbong.pro.constant.XbbProConstant;
import com.xbongbong.pro.enums.DistributorMarkEnum;
import com.xbongbong.pro.enums.errorcodes.ProductErrorCodeEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.formdata.pojo.dto.CheckDateDTO;
import com.xbongbong.pro.formdata.pojo.dto.DefaultOwnerAndCoUserGetDTO;
import com.xbongbong.pro.formdata.pojo.dto.FieldExistDataDTO;
import com.xbongbong.pro.formdata.pojo.dto.FormDataDetailDTO;
import com.xbongbong.pro.formdata.pojo.dto.InheritRuleDTO;
import com.xbongbong.pro.formdata.pojo.dto.SpecificationDTO;
import com.xbongbong.pro.formdata.pojo.vo.CheckDateVO;
import com.xbongbong.pro.formdata.pojo.vo.DefaultOwnerAndCoUserGetVO;
import com.xbongbong.pro.formdata.pojo.vo.FieldExistDataVO;
import com.xbongbong.pro.formdata.pojo.vo.FormDataDetailVO;
import com.xbongbong.pro.formdata.pojo.vo.InheritRuleVO;
import com.xbongbong.pro.formdata.pojo.vo.OtherDataListVO;
import com.xbongbong.pro.fundtransfer.pojo.dto.CheckTransferDateDTO;
import com.xbongbong.pro.fundtransfer.pojo.vo.CheckTransferDateVO;
import com.xbongbong.pro.oriStock.pojo.OriStockSaveDTO;
import com.xbongbong.pro.payment.pojo.dto.PaymentWriteOffDTO;
import com.xbongbong.pro.payment.pojo.vo.PaymentWriteOffVO;
import com.xbongbong.pro.warehouse.pojo.vo.WarehouseListVO;
import com.xbongbong.pro.weblist.pojo.dto.CustomerRepeatDTO;
import com.xbongbong.pro.weblist.pojo.dto.DataInfoDTO;
import com.xbongbong.pro.weblist.pojo.dto.RepeatToolFieldGetDTO;
import com.xbongbong.pro.weblist.pojo.dto.SaasBaseDTO;
import com.xbongbong.pro.weblist.pojo.vo.CustomerRepeatVO;
import com.xbongbong.pro.weblist.pojo.vo.DataInfoVO;
import com.xbongbong.pro.weblist.pojo.vo.RepeatFieldListVO;
import com.xbongbong.pro.weblist.pojo.vo.WaitNumberVO;
import com.xbongbong.saas.service.CustomerService;
import com.xbongbong.saas.service.OriStockService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Map;
import java.util.Objects;

/**
 * @author: wufeng
 * @date: 2018/9/4 19:44
 * @desrcption: 表单数据
 */
@RestController
@RequestMapping(XbbProConstant.API_ROOT_PREFIX + "/form/data")
public class PaasFormDataController {

    private static final Logger LOG = LoggerFactory.getLogger(PaasFormDataController.class);

    @Resource
    private PaasFormDataService paasFormDataService;
    @Resource
    private PaasRedisHelper paasRedisHelper;
    @Resource
    private ProFormDataService proFormDataService;
    @Resource
    private OriStockService oriStockService;
    @Resource
    private CustomerService customerService;
    @Resource
    private LinkDataService linkDataService;
    @Autowired
    private Map<Integer, BusinessDetailBaseInfoService> businessDetailBaseInfoMap;
    @Resource
    private PaasFormAttrTrashService paasFormAttrTrashService;

    /**
     * 获取数据列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String list(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<PaasFormDataEsListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                PaasFormDataEsListVO formDataListVO = paasFormDataService.listByEs(formDataListDTO);
                response = new XbbResponse<>(formDataListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取数据列表
     * @param defaultOwnerAndCoUserGetDTO
     * @param
     * @param br
     * @return
     */
    @RequestMapping(value = "/defaultOwnerAndCoUser/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getDefaultOwnerAndCoUser(@RequestBody @Valid DefaultOwnerAndCoUserGetDTO defaultOwnerAndCoUserGetDTO, BindingResult br) {
        XbbResponse<DefaultOwnerAndCoUserGetVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                DefaultOwnerAndCoUserGetVO defaultOwnerAndCoUserGetVO = paasFormDataService.getDefaultOwnerAndCoUser(defaultOwnerAndCoUserGetDTO);
                response = new XbbResponse<>(defaultOwnerAndCoUserGetVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取继承关系，用于联合新建业务，判断下游的继承规则
     * @param inheritRuleDTO
     * @param
     * @param br
     * @return
     */
    @RequestMapping(value = "/getInheritRule", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getInheritRule(@RequestBody @Valid InheritRuleDTO inheritRuleDTO, BindingResult br) {
        XbbResponse<InheritRuleVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                InheritRuleVO inheritRuleVO = paasFormDataService.getInheritRule(inheritRuleDTO);
                response = new XbbResponse<>(inheritRuleVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }



    /**
     * 关联查询
     * @param linkDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/filter/link/search", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String filterLinkSearch(@RequestBody @Valid LinkSearchListDTO linkDataListDTO, BindingResult br) {
        XbbResponse<LinkSearchListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(linkDataListDTO.getSaasMark(), linkDataListDTO.getBusinessType(), linkDataListDTO.getMenuId(), linkDataListDTO.getDistributorMark());
                LinkSearchListVO linkDataVO = linkDataService.filterLinkSearch(linkDataListDTO);
                response = new XbbResponse<>(linkDataVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 关联数据
     * @param linkDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/filter/link/data", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String filterLinkData(@RequestBody @Valid LinkDataListDTO linkDataListDTO, BindingResult br) {
        XbbResponse<LinkDataListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(linkDataListDTO.getLinkInfo().getLinkSaasMark(), linkDataListDTO.getLinkInfo().getLinkBusinessType(), linkDataListDTO.getLinkInfo().getLinkMenuId(), linkDataListDTO.getDistributorMark());
                LinkDataListVO linkDataVO = linkDataService.filterLinkData(linkDataListDTO);
                response = new XbbResponse<>(linkDataVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 流程流转条件根据字段检索相应的数据
     * @return
     */
    @RequestMapping(value = "/condition/search", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String searchDataInProcessCondition(@RequestBody @Valid SearchDataInConditionDTO searchDataInConditionDTO, BindingResult br){
        XbbResponse<SearchDataInConditionVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(searchDataInConditionDTO.getSaasMark(), searchDataInConditionDTO.getBusinessType(), searchDataInConditionDTO.getMenuId(), searchDataInConditionDTO.getDistributorMark());
                SearchDataInConditionVO searchDataInConditionVO = paasFormDataService.searchDataInProcessCondition(searchDataInConditionDTO);
                response = new XbbResponse<>(searchDataInConditionVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 数据列表根据字段返回可以选择的数据
     * @return
     */
    @RequestMapping(value = "/conditionList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String dataConditionList(@RequestBody @Valid SearchDataInConditionDTO searchDataInConditionDTO, BindingResult br){
        XbbResponse<SearchDataInConditionVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(searchDataInConditionDTO.getSaasMark(), searchDataInConditionDTO.getBusinessType(), searchDataInConditionDTO.getMenuId(), searchDataInConditionDTO.getDistributorMark());
                SearchDataInConditionVO searchDataInConditionVO = proFormDataService.dataConditionList(searchDataInConditionDTO);
                response = new XbbResponse<>(searchDataInConditionVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
    @RequestMapping(value = "/dataSetConditionList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String dataSetConditionList(@RequestBody @Valid SearchDataSetInConditionDTO searchDataSetInConditionDTO, BindingResult br){
        XbbResponse<SearchDataInConditionVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(searchDataSetInConditionDTO.getSaasMark(), searchDataSetInConditionDTO.getBusinessType(), searchDataSetInConditionDTO.getMenuId(), searchDataSetInConditionDTO.getDistributorMark());
                SearchDataInConditionVO searchDataInConditionVO = proFormDataService.dataSetConditionList(searchDataSetInConditionDTO);
                response = new XbbResponse<>(searchDataInConditionVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
    @RequestMapping(value = "/boardConditionList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String boardConditionList(@RequestBody @Valid SearchBoardConditionDTO searchDataSetInConditionDTO, BindingResult br){
        XbbResponse<SearchDataInConditionVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(searchDataSetInConditionDTO.getSaasMark(), searchDataSetInConditionDTO.getBusinessType(), searchDataSetInConditionDTO.getMenuId(), searchDataSetInConditionDTO.getDistributorMark());
                SearchDataInConditionVO searchDataInConditionVO = proFormDataService.dataSetConditionList(searchDataSetInConditionDTO);
                response = new XbbResponse<>(searchDataInConditionVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 根据fieldType返回可以选择的组织架构数据
     * @param searchInConditionDTO
     * @param br
     * @return java.lang.String
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    @RequestMapping(value = "/organization/conditionList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String dataConditionList(@RequestBody @Valid SearchInConditionDTO searchInConditionDTO, BindingResult br){
        XbbResponse<SearchDataInConditionVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                SearchDataInConditionVO searchDataInConditionVO = proFormDataService.organizationConditionList(searchInConditionDTO);
                response = new XbbResponse<>(searchDataInConditionVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 关联线索（市场活动详情tab）
     * 数据列表根据字段返回可以选择的数据
     * @return
     */
    @RequestMapping(value = "/relationClue/conditionList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String clueDataConditionList(@RequestBody @Valid SearchDataInConditionDTO searchDataInConditionDTO, BindingResult br){
        XbbResponse<SearchDataInConditionVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(searchDataInConditionDTO.getSaasMark(), searchDataInConditionDTO.getBusinessType(), searchDataInConditionDTO.getMenuId(), DistributorMarkEnum.OTHER.getCode());
                SearchDataInConditionVO searchDataInConditionVO = proFormDataService.relClueDataConditionList(searchDataInConditionDTO);
                response = new XbbResponse<>(searchDataInConditionVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 列表分组获取数据接口
     * @param searchDataInConditionDTO
     * @param br
     * @return
     * @throws XbbException
     */
    @RequestMapping(value = "/list/group", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String listGroupGetData(@RequestBody @Valid SearchDataInConditionDTO searchDataInConditionDTO, BindingResult br) throws XbbException {
        XbbResponse<SearchDataInConditionVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(searchDataInConditionDTO.getSaasMark(), searchDataInConditionDTO.getBusinessType(), searchDataInConditionDTO.getMenuId(), searchDataInConditionDTO.getDistributorMark());
                SearchDataInConditionVO searchDataInConditionVO = paasFormDataService.searchDataInProcessCondition(searchDataInConditionDTO);
                response = new XbbResponse<>(searchDataInConditionVO);
            } catch (XbbException e){
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取数据总数
     * @param formCountGetDTO
     * @param br
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/count", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String count(@RequestBody @Valid FormCountGetDTO formCountGetDTO, BindingResult br) throws Exception {
        XbbResponse<FormCountGetVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormCountGetVO formCountGetVO = this.paasFormDataService.count(formCountGetDTO);
                response = new XbbResponse<>(formCountGetVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 新建表单数据（需要返回表单字段描述）
     * @param formDataAddGetDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/add/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String addGet(@RequestBody @Valid FormDataAddGetDTO formDataAddGetDTO, BindingResult br) {
        XbbResponse<FormDataAddGetVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataAddGetDTO.getSaasMark(), formDataAddGetDTO.getBusinessType(), formDataAddGetDTO.getMenuId(), formDataAddGetDTO.getDistributorMark());
                FormDataAddGetVO formDataAddGetVO= paasFormDataService.addGet(formDataAddGetDTO);
                response = new XbbResponse<>(formDataAddGetVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 快捷新建表单数据（需要返回表单字段描述，查重快速新建）
     * @param formDataFastAddGetDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/fastAdd/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String fastAddGet(@RequestBody @Valid FormDataFastAddGetDTO formDataFastAddGetDTO, BindingResult br) {
        XbbResponse<FormDataAddGetVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataFastAddGetDTO.getSaasMark(), formDataFastAddGetDTO.getBusinessType(), formDataFastAddGetDTO.getMenuId(), formDataFastAddGetDTO.getDistributorMark());
                FormDataAddGetVO formDataAddGetVO = paasFormDataService.fastAddGet(formDataFastAddGetDTO);
                response = new XbbResponse<>(formDataAddGetVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 编辑表单数据（需要返回表单字段描述）
     * @param formDataUpdateGetDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/update/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String updateGet(@RequestBody @Valid FormDataUpdateGetDTO formDataUpdateGetDTO, BindingResult br) {
        XbbResponse<FormDataUpdateGetVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataUpdateGetDTO.getSaasMark(), formDataUpdateGetDTO.getBusinessType(), formDataUpdateGetDTO.getMenuId(), formDataUpdateGetDTO.getDistributorMark());
                FormDataUpdateGetVO formDataUpdateGetVO = paasFormDataService.updateGet(formDataUpdateGetDTO);
                response = new XbbResponse<>(formDataUpdateGetVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 按钮类型字段编辑表单数据（需要返回表单字段描述）
     * @param buttonGetDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/button/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String buttonGet(@RequestBody @Valid ButtonGetDTO buttonGetDTO, BindingResult br) {
        XbbResponse<ButtonGetVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ButtonGetVO buttonGetVO = paasFormDataService.buttonGet(buttonGetDTO);
                response = new XbbResponse<>(buttonGetVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * 获取数据详情
     * @param formDataGetDTO
     * @param br
     * @returnadd
     */

    @RequestMapping(value = "/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String get(@RequestBody @Valid FormDataGetDTO formDataGetDTO, BindingResult br) {
        XbbResponse<FormDataGetVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataGetDTO.getSaasMark(), formDataGetDTO.getBusinessType(), formDataGetDTO.getMenuId(), formDataGetDTO.getDistributorMark());
                FormDataGetVO formDataGetVO = paasFormDataService.get(formDataGetDTO);

                response = new XbbResponse<>(formDataGetVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取数据详情tab页面
     * @param formDataDetailDTO
     * @param br
     * @returnadd
     */

    @RequestMapping(value = "/detail", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String detail(@RequestBody @Valid FormDataDetailDTO formDataDetailDTO, BindingResult br) {
        XbbResponse<FormDataDetailVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataDetailDTO.getSaasMark(),formDataDetailDTO.getBusinessType(), formDataDetailDTO.getMenuId(), formDataDetailDTO.getDistributorMark());
                FormDataDetailVO formDataDetailVO = paasFormDataService.getDetail(formDataDetailDTO);
                response = new XbbResponse<>(formDataDetailVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 删除单条数据
     * @param formDataDeleteDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String delete(@RequestBody @Valid FormDataDeleteDTO formDataDeleteDTO, BindingResult br) {
        XbbResponse<FormDataDeleteVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormDataDeleteVO formDataDeleteVO = paasFormDataService.delete(formDataDeleteDTO);
                response = new XbbResponse<>(formDataDeleteVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 保存单条数据
     * @param formDataSaveDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String add(@RequestBody @Valid FormDataAddDTO formDataSaveDTO, BindingResult br) {
        XbbResponse<FormDataAddVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(formDataSaveDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(formDataSaveDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }

                TransmittableThreadLocalUtil.setValue(formDataSaveDTO.getSaasMark(), formDataSaveDTO.getBusinessType(), formDataSaveDTO.getMenuId(), formDataSaveDTO.getDistributorMark());
                FormDataAddVO formDataSaveVO = paasFormDataService.add(formDataSaveDTO);
                response = new XbbResponse<>(formDataSaveVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 保存单条数据
     * @param formDataUpdateDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String update(@RequestBody @Valid FormDataUpdateDTO formDataUpdateDTO, BindingResult br) {
        XbbResponse<FormDataUpdateVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataUpdateDTO.getSaasMark(), formDataUpdateDTO.getBusinessType(), formDataUpdateDTO.getMenuId(), formDataUpdateDTO.getDistributorMark());
                FormDataUpdateVO formDataUpdateVO = paasFormDataService.update(formDataUpdateDTO);
                response = new XbbResponse<>(formDataUpdateVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 快速编辑
     * @param formDataFastUpdateDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/fast/update", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String fastUpdate(@RequestBody @Valid FormDataFastUpdateDTO formDataFastUpdateDTO, BindingResult br) {
        XbbResponse<FormDataFastUpdateVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormDataFastUpdateVO formDataFastUpdateVO = paasFormDataService.fastUpdate(formDataFastUpdateDTO);
                response = new XbbResponse<>(formDataFastUpdateVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 更改负责人
     * @param formDataOwnerDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/update/owner", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String updateOwner(@RequestBody @Valid FormDataOwnerDTO formDataOwnerDTO, BindingResult br) {
        XbbResponse<FormDataOwnerVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormDataOwnerVO formDataOwnerVO = paasFormDataService.updateOwner(formDataOwnerDTO);
                response = new XbbResponse<>(formDataOwnerVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * 下拉框-选项-联动其他表单
     */
    @RequestMapping(value = "link/form/data", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String linkFormData(@RequestBody @Valid LinkFormDataDTO linkFormDataDTO, BindingResult br) {
        XbbResponse<LinkFormDataVO> response;
        if(br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                LinkFormPoJo linkFormPoJo = linkFormDataDTO.getLinkForm();
                TransmittableThreadLocalUtil.setValue(linkFormPoJo.getSourceSaasMark(), linkFormPoJo.getSourceBusinessType(), linkFormPoJo.getSourceMenuId(), linkFormDataDTO.getDistributorMark());
                LinkFormDataVO linkFormDataVO = paasFormDataService.linkFormData(linkFormDataDTO);
                response = new XbbResponse<>(linkFormDataVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 数据联动
     */
    @RequestMapping(value = "link/rely/data", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String linkRelyData(@RequestBody @Valid LinkRelyDataDTO linkRelyDataDTO, BindingResult br) {
        XbbResponse<LinkRelyDataVO> response;
        if(br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                RelyPoJo relyPoJo = linkRelyDataDTO.getRely();
                TransmittableThreadLocalUtil.setValue(relyPoJo.getSourceSaasMark(), relyPoJo.getSourceBusinessType(), relyPoJo.getSourceMenuId(), linkRelyDataDTO.getDistributorMark());
                LinkRelyDataVO linkRelyDataVO= paasFormDataService.linkRelyData(linkRelyDataDTO);
                response = new XbbResponse<>(linkRelyDataVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
    /**
     * 工单联系方式
     */
    @RequestMapping(value = "linkWorkOrderPhone", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String linkWorkOrderPhone(@RequestBody @Valid LinkWorkOrderPhoneDTO linkWorkOrderPhoneDTO, BindingResult br) {
        XbbResponse<LinkRelyDataWorkOrderPhoneVO> response;
        if(br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                LinkRelyDataWorkOrderPhoneVO linkRelyDataWorkOrderPhoneVO= paasFormDataService.linkWorkOrderPhone(linkWorkOrderPhoneDTO);
                response = new XbbResponse<>(linkRelyDataWorkOrderPhoneVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 查询重复信息
     * @param formDataRepeatDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/repeat", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String repeat(@RequestBody @Valid FormDataRepeatDTO formDataRepeatDTO, BindingResult br) {
        XbbResponse<CheckRepeatVO> response;
        if(br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                formDataRepeatDTO.setIsEdit(false);
                CheckRepeatVO checkRepeatVO = paasFormDataService.repeat(formDataRepeatDTO);
                response = new XbbResponse<>(checkRepeatVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 数据汇总
     * @param formDataSummaryDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/summary", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String summary(@RequestBody @Valid FormDataSummaryDTO formDataSummaryDTO, BindingResult br) {
        XbbResponse<FormDataSummaryVO> response;
        if(br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataSummaryDTO.getSaasMark(), formDataSummaryDTO.getBusinessType(), formDataSummaryDTO.getMenuId(), formDataSummaryDTO.getDistributorMark());
                FormDataSummaryVO formDataSummaryVO = paasFormDataService.getFormDataSummary(formDataSummaryDTO);
                response = new XbbResponse<>(formDataSummaryVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 子表单内的数据汇总
     * @param
     * @param br
     * @return
     */
    @RequestMapping(value = "/subSummary", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String subSummary(@RequestBody @Valid FormDataSubSummaryGetDTO formDataSubSummaryGetDTO, BindingResult br) {
        XbbResponse<FormDataSummaryVO> response;
        if(br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormDataSummaryVO formDataSummaryVO = paasFormDataService.getFormDataSubSummary(formDataSubSummaryGetDTO);
                response = new XbbResponse<>(formDataSummaryVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 审批打印子表单数字字段汇总
     *
     * @param
     * @param br
     * @throws
     * @return
     * @author: 曹远远
     * @date: 2020-04-28
     * @since:
     * @version:
     */
    @RequestMapping(value = "/subPrintSummary", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String subPrintSummary(@RequestBody @Valid ApprovePrintSubSummaryGetDTO approvePrintSubSummaryGetDTO, BindingResult br) {
        XbbResponse<FormDataSummaryVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try{
                FormDataSummaryVO formDataSummaryVO = paasFormDataService.getFormDataPrintSubSummary(approvePrintSubSummaryGetDTO);
                response = new XbbResponse<>(formDataSummaryVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 列表表头
     * @param dataInfoDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/info", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String info(@RequestBody @Valid DataInfoDTO dataInfoDTO, BindingResult br) {
        XbbResponse<DataInfoVO> response;
        if(br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                DataInfoVO dataInfoVO = paasFormDataService.dataInfo(dataInfoDTO);
                response = new XbbResponse<>(dataInfoVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 客户列表查重渲染
     * @param customerRepeatDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/customerRepeat", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String customerRepeat(@RequestBody @Valid CustomerRepeatDTO customerRepeatDTO, BindingResult br) {
        XbbResponse<CustomerRepeatVO> response;
        if(br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                CustomerRepeatVO repeatVO = paasFormDataService.customerRepeat(customerRepeatDTO);
                response = new XbbResponse<>(repeatVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 保存单条数据
     * @param formDataSaveDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/addBatch", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String addBatch(@RequestBody @Valid FormDataAddDTO formDataSaveDTO, BindingResult br) {
        XbbResponse<FormDataAddVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(formDataSaveDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(formDataSaveDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }

                FormDataAddVO formDataSaveVO = paasFormDataService.addBatch(formDataSaveDTO);
                response = new XbbResponse<>(formDataSaveVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * Description: 产品扫描
     * @param productListDataDTO
     * @param br
     * @author 魏荣杰
     * @date 2019/5/29 10:29
     * @since v1.0
     */
    @RequestMapping(value = "/product/scanBarcode", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String scanBarcode(@RequestBody @Valid ProductListDataDTO productListDataDTO, BindingResult br) {
        XbbResponse<PaasFormDataEsListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(productListDataDTO.getSaasMark(), productListDataDTO.getBusinessType(), null, productListDataDTO.getDistributorMark());
                PaasFormDataEsListVO paasFormDataEsListVO = paasFormDataService.getProductList(productListDataDTO);
                if (Objects.nonNull(paasFormDataEsListVO) && paasFormDataEsListVO.getPaasFormDataESList().size() == 0) {
                    throw new XbbException(ProductErrorCodeEnum.API_ERROR_205022);
                }
                response = new XbbResponse<>(paasFormDataEsListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * Description: 检验字段是否存在数据
     * @param fieldExistDataDTO
     * @param br
     * @author 吴峰
     * @date 2019/7/4 11:09
     * @since v1.0
     */
    @RequestMapping(value = "/fieldExistData", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String fieldExistData(@RequestBody @Valid FieldExistDataDTO fieldExistDataDTO, BindingResult br) {
        XbbResponse<FieldExistDataVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FieldExistDataVO fieldExistDataVO = paasFormAttrTrashService.fieldExistData(fieldExistDataDTO);
                response = new XbbResponse<>(fieldExistDataVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
    * @Description: 检验能否不可见或不启用规格字段
    * @Param: [fieldExistDataDTO, br]
    * @return: java.lang.String
    * @Author: cyy
    * @Date: 2019/11/15
    */
    @RequestMapping(value = "/canDeleteSpecification", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String canDeleteSpecification(@RequestBody @Valid SpecificationDTO specificationDTO, BindingResult br) {
        XbbResponse<FieldExistDataVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FieldExistDataVO fieldExistDataVO = proFormDataService.canDeleteSpecification(specificationDTO);
                response = new XbbResponse<>(fieldExistDataVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    @RequestMapping(value = "/waitNumber", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String waitNumber(@RequestBody @Valid SaasBaseDTO saasBaseDTO, BindingResult br) {
        XbbResponse<WaitNumberVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(saasBaseDTO.getSaasMark(), saasBaseDTO.getSubBusinessType(), null, saasBaseDTO.getDistributorMark());
                WaitNumberVO waitNumber = proFormDataService.waitNumber(saasBaseDTO);
                response = new XbbResponse<>(waitNumber);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
    * @Description: 历史规格值
    * @Param: [saasBaseDTO, br]
    * @return: java.lang.String
    * @Author: cyy
    * @Date: 2019/9/10
    */
    @RequestMapping(value = "/specificationHistory", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String specificationHistory(@RequestBody @Valid SpecificationHistoryDTO specificationHistoryDTO, BindingResult br) {
        XbbResponse<SpecificationHistoryVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                SpecificationHistoryVO specificationHistoryVO = proFormDataService.specificationHistory(specificationHistoryDTO);
                response = new XbbResponse<>(specificationHistoryVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
    /**
     * @Description: 仓库下期初库存的保存
     * @Param: [saasBaseDTO, br]
     * @return: java.lang.String
     * @Author: cyy
     * @Date: 2019/9/10
     */
    @RequestMapping(value = "/addOriStock", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String addOriStock(@RequestBody @Valid OriStockSaveDTO oriStockSaveDTO, BindingResult br) {
        XbbResponse<FormDataAddVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormDataAddVO formDataAddVO = oriStockService.add(oriStockSaveDTO);
                response = new XbbResponse<>(formDataAddVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
    /**
     * @Description: helloWorld
     * @Param: [saasBaseDTO, br]
     * @return: java.lang.String
     * @Author: zhb
     * @Date: 2020/3/25
     */
    @RequestMapping(value = "/helloWorld", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String helloWorld() {
        LOG.warn("helloWorld-----------------------------------");
        return "helloWorld";
    }

    /**
     * 校检仓库是否可用
     * @param warehouseCheckDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/checkWarehouse", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String checkWarehouse(@RequestBody @Valid WarehouseCheckDTO warehouseCheckDTO, BindingResult br) {
        XbbResponse<WarehouseListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                WarehouseListVO warehouseListVO = paasFormDataService.checkWarehouse(warehouseCheckDTO);
                response = new XbbResponse<>(warehouseListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
    /**
     * @Description: 获取其他数据
     * @Param: [saasBaseDTO, br]
     * @return: java.lang.String
     * @author: wufeng
     * @date 2020/3/27 22:05
     */
    @RequestMapping(value = "/otherDataList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String otherDataList(@RequestBody @Valid FormDataListDTO otherDataListDTO, BindingResult br) {
        XbbResponse<OtherDataListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                OtherDataListVO otherDataListVO = proFormDataService.otherDataList(otherDataListDTO);
                response = new XbbResponse<>(otherDataListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 下拉框-搜索工商查询匹配
     * @param businessFormDataDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/business/data", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String businessComboData(@RequestBody @Valid BusinessFormDataDTO businessFormDataDTO, BindingResult br) {
        XbbResponse<LinkFormDataVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(businessFormDataDTO.getSaasMark(), businessFormDataDTO.getBusinessType(), businessFormDataDTO.getMenuId(), businessFormDataDTO.getDistributorMark());
                LinkFormDataVO linkFormDataVO = proFormDataService.businessComboData(businessFormDataDTO);
                response = new XbbResponse<>(linkFormDataVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     *  获取合并客户数据
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/customer/merge", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getCustomerMetge(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<CustomerMergeVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), DistributorMarkEnum.OTHER.getCode());
                CustomerMergeVO customerMergeVO = paasFormDataService.getCustomerMerge(formDataListDTO);
                response = new XbbResponse<>(customerMergeVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    @RequestMapping(value = "/customer/merge/set", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getCustomerMetge(@RequestBody @Valid CustomerMergeDTO customerMergeDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                BaseVO baseVO = customerService.customerMerge(customerMergeDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
    /**
     * 应收款核销
     * @param paymentWriteOffDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/payment/writeOff", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String paymentWriteOff(@RequestBody @Valid PaymentWriteOffDTO paymentWriteOffDTO, BindingResult br) {
        XbbResponse<PaymentWriteOffVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(paymentWriteOffDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(paymentWriteOffDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }

                PaymentWriteOffVO paymentWriteOff = paasFormDataService.paymentWriteOff(paymentWriteOffDTO);
                response = new XbbResponse<>(paymentWriteOff);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     *  查重工具获取查重参数
     * @param repeatToolFieldGetDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/repeatTool/repeatField", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getRepeatField(@RequestBody @Valid RepeatToolFieldGetDTO repeatToolFieldGetDTO, BindingResult br) {
        XbbResponse<RepeatFieldListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                RepeatFieldListVO repeatFieldListVO = paasFormDataService.getRepeatField(repeatToolFieldGetDTO);
                response = new XbbResponse<>(repeatFieldListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 资金调拨单 - 校验调拨日期
     * @param checkTransferDateDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/fundTransfer/checkTransferDate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String checkTransferDate(@RequestBody @Valid CheckTransferDateDTO checkTransferDateDTO, BindingResult br) {
        XbbResponse<CheckTransferDateVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                CheckTransferDateVO checkDateVO = paasFormDataService.checkTransferDate(checkTransferDateDTO);
                response = new XbbResponse<>(checkDateVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }



    /**
     * 获取当前日期之后是否还有单据
     * @param checkDateDTO
     * @param br
     * @returnadd
     */

    @RequestMapping(value = "/checkDate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String checkDate(@RequestBody @Valid CheckDateDTO checkDateDTO, BindingResult br) {
        XbbResponse<CheckDateVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                CheckDateVO checkDateVO = paasFormDataService.checkDate(checkDateDTO);
                response = new XbbResponse<>(checkDateVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * 删除时间获取当前日期之后是否还有单据
     * @param checkDateDTO
     * @param br
     * @returnadd
     */
    @RequestMapping(value = "/delete/checkDate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String deleteCheckDate(@RequestBody @Valid CheckDateDTO checkDateDTO, BindingResult br) {
        XbbResponse<CheckDateVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {

                CheckDateVO checkDateVO = paasFormDataService.deleteCheckDate(checkDateDTO);
                response = new XbbResponse<>(checkDateVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
}
